//
//  XMEarningsViewController.m
//  gpos_app
//
//  Created by apple on 2018/8/16.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "XMEarningsViewController.h"
#import "Masonry.h"
#import "earningViewCell.h"
#import "GPosAPI.h"
#import "PopupView.h"
#import "homeModel.h"
#import "WKProgressHUD.h"
#import "XMRegisterViewController.h"
#import "SVProgressHUD.h"

#import "YKLineChartView.h"
#import "YKUIConfig.h"
#import "YKLineDataObject.h"

@interface XMEarningsViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)YKLineChartView *chartView;
@property (nonatomic,strong)UIButton * tuButton;
@property (nonatomic,strong)UIButton * biaoButton;

@property (nonatomic,strong)UIButton * jyzButton;
@property (nonatomic,strong)UIImageView * jtImageView;
@property (nonatomic,strong)UIView * jyzxxView;

@property (nonatomic,strong)UIView * bottomBjtView;
@property (nonatomic,strong)UITableView * tableView;
@property (nonatomic,strong)NSDictionary * params;
@property (nonatomic,strong)UILabel * jyzLabel;
@property (nonatomic,strong)NSString * number;
@property (nonatomic,strong)NSMutableArray * modelArr;
@property(strong,nonatomic)WKProgressHUD *hud;
@property (nonatomic,strong)UILabel *syLabel;
@property (nonatomic,strong)UILabel *syGposLabel;
@property (nonatomic,strong)UILabel *kjLabel;
@property (nonatomic,strong)UILabel * kjnrLabel;
@property (nonatomic,strong)UILabel * jxnrLabel;

@property (nonatomic,strong)NSString * datanul;
@property (nonatomic,strong)NSString * option;
@property (nonatomic,strong)UIView * tuView;

@property (nonatomic,strong)NSMutableArray * timeArr;
@property (nonatomic,strong)NSMutableArray * NumberArr1;
@property (nonatomic,strong)NSMutableArray * NumberArr;

@property (nonatomic,strong)NSString * colorStr;

@end

@implementation XMEarningsViewController
//改变状态栏
-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
}
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(walkVCClick:) name:@"buttonIndex" object:nil];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    self.number =@"7";
    self.option = @"近一周";
    self.colorStr = @"1";
    if ([self.isOn isEqualToString:@"0"]) {
        
        self.title = @"总收益";
    }else {
        
        self.title = @"昨日收益";
    }
    
    [self loadData];
    
    
    
    
}

- (void)walkVCClick:(NSNotification *)noti

{
//    self.modelArr = [[NSMutableArray alloc] init];
//    self.modelArr = (NSMutableArray *)[[self.modelArr reverseObjectEnumerator] allObjects];
    NSDictionary * dic = [noti userInfo];
    NSString * str = [dic objectForKey:@"index"];
    NSInteger index =0;
    index = [str integerValue];
    if ([self.isOn isEqualToString:@"0"]) {
        if (index==0||index==self.modelArr.count+1) {
            
            return;
        }

        self.syLabel.text = [NSString stringWithFormat:@"总收益(%d)",[self.modelArr[index-1] datatime]];
        
        self.syGposLabel.text = [NSString stringWithFormat:@"%@",[self.modelArr[index-1] totalIncome]];
        
        self.kjnrLabel.text =[NSString stringWithFormat:@"%@",[self.modelArr[index-1] minerTotalIncome]];
        
        self.jxnrLabel.text = [NSString stringWithFormat:@"%@",[self.modelArr[index-1] campaignTotalIncome]];
        
    }else {
        if (index==0||index==self.modelArr.count+1) {
            
            return;
        }
        self.syLabel.text = [NSString stringWithFormat:@"昨日收益(%d)",[self.modelArr[index-1] datatime]];

        self.syGposLabel.text = [NSString stringWithFormat:@"%@",[self.modelArr[index-1] yesterdayTotal]];

        self.kjnrLabel.text =[NSString stringWithFormat:@"%@",[self.modelArr[index-1] minerIncome]];
        self.jxnrLabel.text = [NSString stringWithFormat:@"%@",[self.modelArr[index-1] campaignIncome]];
    }

    NSLog(@"点我--%@",self.NumberArr);
    
}

-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)loadData{
    self.timeArr = [[NSMutableArray alloc] init];
    self.NumberArr = [[NSMutableArray alloc] init];
    self.NumberArr1 = [[NSMutableArray alloc] init];

    
//    self.tuView = [[UIView alloc] init];
    self.jyzLabel.text = @"";
    int user = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
    NSDictionary * params = @{@"userId"  : @(user),
                              @"number" :self.number
                              };
    [SVProgressHUD showWithStatus:@"加载中"];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
    [GPosAPI requestAllIncomeWithParams:params andCallback:^(id obj) {
        NSLog(@"obj---%@",obj);
        if (obj == nil) {
            self.hud=[WKProgressHUD popMessage:@"请求失败" inView:self.view duration:1 animated:YES];
            
        }else {
            [SVProgressHUD dismiss];
            if ([[obj objectForKey:@"code"] intValue] == 200) {
                self.modelArr = [[NSMutableArray alloc] init];
                self.datanul = [obj objectForKey:@"data"];
                NSArray * arr = [[NSArray alloc] init];
                arr = [obj objectForKey:@"data"];
                
                for (NSDictionary * dic in arr) {
                    homeModel *model = [[homeModel alloc] init];
                    model.campaignIncome = [dic objectForKey:@"campaignIncome"];
                    model.campaignTotalIncome = [dic objectForKey:@"campaignTotalIncome"];
                    
                    NSDecimalNumber * number = [dic objectForKey:@"minerIncome"];
//                    model.amount = [NSString stringWithFormat:@"%@",@(number.floatValue)];
                    model.minerIncome = [NSString stringWithFormat:@"%@",@(number.floatValue)];
                    
                    NSDecimalNumber * number1 = [dic objectForKey:@"minerTotalIncome"];
                    model.minerTotalIncome = [NSString stringWithFormat:@"%@",@(number1.floatValue)];
                    
                    model.datatime = [[dic objectForKey:@"time"] intValue];
                    
                    NSDecimalNumber * number2 = [dic objectForKey:@"totalIncome"];
                    model.totalIncome = [NSString stringWithFormat:@"%@",@(number2.floatValue)];
                    
                    NSDecimalNumber * number3 = [dic objectForKey:@"yesterdayTotal"];
                    model.yesterdayTotal = [NSString stringWithFormat:@"%@",@(number3.floatValue)];

                    [self.modelArr addObject:model];
                    [self.timeArr addObject:[NSString stringWithFormat:@"%@",[dic objectForKey:@"time"]]];
                    [self.NumberArr addObject:model.totalIncome];
                    [self.NumberArr1 addObject:model.yesterdayTotal];
                    
                    
                }
                [self.tableView reloadData];
                NSLog(@"图片--%@",self.datanul);
            }else if ([[obj objectForKey:@"code"] intValue] == 401 || [[obj objectForKey:@"code"] intValue] == 402){
                [SVProgressHUD dismiss];
                UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                //storyboard里的ID
                XMRegisterViewController *vc = [mainStory instantiateInitialViewController];
                vc.navigationController.navigationBarHidden=NO;
                //                    //设置当前窗口的根控制器
                
                [UIApplication sharedApplication].keyWindow.rootViewController=vc;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            
            }else {
                [SVProgressHUD dismiss];
                self.hud=[WKProgressHUD popMessage:[obj objectForKey:@"message"] inView:self.view duration:1 animated:YES];
            }
            
        }
         [self topLoadView];
     
    }];
    
}

//刷新图表
- (void)tuData{
    self.timeArr = [[NSMutableArray alloc] init];
    self.NumberArr = [[NSMutableArray alloc] init];
    self.NumberArr1 = [[NSMutableArray alloc] init];
    
    
    //    self.tuView = [[UIView alloc] init];
    self.jyzLabel.text = @"";
    int user = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
    NSDictionary * params = @{@"userId"  : @(user),
                              @"number" :self.number
                              };
    [SVProgressHUD showWithStatus:@"加载中"];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
    [GPosAPI requestAllIncomeWithParams:params andCallback:^(id obj) {
        NSLog(@"obj---%@",obj);
        if (obj == nil) {
            self.hud=[WKProgressHUD popMessage:@"请求失败" inView:self.view duration:1 animated:YES];
            
        }else {
            [SVProgressHUD dismiss];
            if ([[obj objectForKey:@"code"] intValue] == 200) {
                self.modelArr = [[NSMutableArray alloc] init];
                self.datanul = [obj objectForKey:@"data"];
                NSArray * arr = [[NSArray alloc] init];
                arr = [obj objectForKey:@"data"];
                
                for (NSDictionary * dic in arr) {
                    homeModel *model = [[homeModel alloc] init];
                    model.campaignIncome = [dic objectForKey:@"campaignIncome"];
                    model.campaignTotalIncome = [dic objectForKey:@"campaignTotalIncome"];
                    
                    NSDecimalNumber * number = [dic objectForKey:@"minerIncome"];
                    //                    model.amount = [NSString stringWithFormat:@"%@",@(number.floatValue)];
                    model.minerIncome = [NSString stringWithFormat:@"%@",@(number.floatValue)];
                    
                    NSDecimalNumber * number1 = [dic objectForKey:@"minerTotalIncome"];
                    model.minerTotalIncome = [NSString stringWithFormat:@"%@",@(number1.floatValue)];
                    
                    model.datatime = [[dic objectForKey:@"time"] intValue];
                    
                    NSDecimalNumber * number2 = [dic objectForKey:@"totalIncome"];
                    model.totalIncome = [NSString stringWithFormat:@"%@",@(number2.floatValue)];
                    
                    NSDecimalNumber * number3 = [dic objectForKey:@"yesterdayTotal"];
                    model.yesterdayTotal = [NSString stringWithFormat:@"%@",@(number3.floatValue)];
                    
                    [self.modelArr addObject:model];
                    [self.timeArr addObject:[NSString stringWithFormat:@"%@",[dic objectForKey:@"time"]]];
                    [self.NumberArr addObject:model.totalIncome];
                    [self.NumberArr1 addObject:model.yesterdayTotal];
                    
                    
                }
                
                [self.tableView reloadData];
                NSLog(@"图片--%@",self.datanul);
            }else if ([[obj objectForKey:@"code"] intValue] == 401 || [[obj objectForKey:@"code"] intValue] == 402){
                [SVProgressHUD dismiss];
                UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                //storyboard里的ID
                XMRegisterViewController *vc = [mainStory instantiateInitialViewController];
                vc.navigationController.navigationBarHidden=NO;
                //                    //设置当前窗口的根控制器
                
                [UIApplication sharedApplication].keyWindow.rootViewController=vc;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }else {
                [SVProgressHUD dismiss];
                self.hud=[WKProgressHUD popMessage:[obj objectForKey:@"message"] inView:self.view duration:1 animated:YES];
            }
            
        }
        
        if ([self.isOn isEqualToString:@"0"]) {
            
            self.syLabel.text = [NSString stringWithFormat:@"总收益(%d)",[self.modelArr[0] datatime]];
            //            NSNumber * nsNumber1 = @([self.modelArr[0] totalIncome]);
            self.syGposLabel.text = [NSString stringWithFormat:@"%@",[self.modelArr[0] totalIncome]];
            //            NSNumber * nsNumber2 = @([self.modelArr[0] minerTotalIncome]);
            self.kjnrLabel.text =[NSString stringWithFormat:@"%@",[self.modelArr[0] minerTotalIncome]];
            //             NSNumber * nsNumber3 = @([self.modelArr[0] campaignTotalIncome]);
            self.jxnrLabel.text = [NSString stringWithFormat:@"%@",[self.modelArr[0] campaignTotalIncome]];
            //        NSLog(@"model---%@",self.modelArr[0]);
            
        }else {
            
            self.syLabel.text = [NSString stringWithFormat:@"昨日收益(%d)",[self.modelArr[0] datatime]];
    
            self.syGposLabel.text = [NSString stringWithFormat:@"%@",[self.modelArr[0] yesterdayTotal]];
            //            NSNumber * nsNumber2 = @([self.modelArr[0] minerIncome]);
            self.kjnrLabel.text =[NSString stringWithFormat:@"%@",[self.modelArr[0] minerIncome]];
            //            NSNumber * nsNumber3 = @([self.modelArr[0] campaignIncome]);
            self.jxnrLabel.text = [NSString stringWithFormat:@"%@",[self.modelArr[0] campaignIncome]];
        }
        
        self.jyzLabel.text = self.option;
        [self bottomLoadView];
        
    }];
    
}

- (void)topLoadView{
    self.syLabel = [[UILabel alloc] init];
    self.syLabel.textAlignment=NSTextAlignmentCenter;
    self.syLabel.textColor = [UIColor grayColor];
    self.syLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:self.syLabel];
    
    self.syGposLabel = [[UILabel alloc] init];
    self.syGposLabel.textAlignment=NSTextAlignmentCenter;
    self.syGposLabel.textColor = [UIColor blackColor];
    self.syGposLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:40];
    [self.view addSubview:self.syGposLabel];
    
    self.kjLabel = [[UILabel alloc] init];
    self.kjLabel.textAlignment=NSTextAlignmentCenter;
    self.kjLabel.textColor = [UIColor blackColor];
    self.kjLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:self.kjLabel];
    
    self.kjnrLabel = [[UILabel alloc] init];
    self.kjnrLabel.textAlignment=NSTextAlignmentCenter;
    self.kjnrLabel.textColor = [UIColor colorWithRed:70/255.0f green:85/255.0f blue:254/255.0f alpha:1];
    self.kjnrLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:self.kjnrLabel];
    
    UILabel * jxLabel = [[UILabel alloc] init];
    jxLabel.textAlignment=NSTextAlignmentCenter;
    jxLabel.textColor = [UIColor blackColor];
    jxLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:jxLabel];
    
   self.jxnrLabel = [[UILabel alloc] init];
    self.jxnrLabel.textAlignment=NSTextAlignmentCenter;
    self.jxnrLabel.textColor = [UIColor colorWithRed:70/255.0f green:85/255.0f blue:254/255.0f alpha:1];
    self.jxnrLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:self.jxnrLabel];
    
    UIView * tbBjView = [[UIView alloc] init];
    tbBjView.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];
    tbBjView.layer.cornerRadius = 5;
    [self.view addSubview:tbBjView];
    
    UIView * sxView = [[UIView alloc] init];
    sxView.backgroundColor = [UIColor grayColor];
    [tbBjView addSubview:sxView];
    
    self.tuButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.tuButton setTitle:@"图" forState:UIControlStateNormal];
    self.tuButton.titleLabel.font = [UIFont systemFontOfSize: 15.0];
   
   
    [tbBjView addSubview:self.tuButton];
    [self.tuButton addTarget:self action:@selector(tuButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
   
    self.biaoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.biaoButton setTitle:@"表" forState:UIControlStateNormal];
    self.biaoButton.titleLabel.font = [UIFont systemFontOfSize: 15.0];
   
    [tbBjView addSubview:self.biaoButton];
    [self.biaoButton addTarget:self action:@selector(biaoButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//    tbBjView.hidden = YES;
    self.jtImageView = [[UIImageView alloc] init];
    self.jtImageView.image = [UIImage imageNamed:@"icon_xiala"];
    [self.view addSubview:self.jtImageView];
    
    self.bottomBjtView = [[UIView alloc] init];
    self.bottomBjtView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.bottomBjtView];
    [self bottomLoadView];
    
    self.jyzLabel = [[UILabel alloc] init];
    self.jyzLabel.textAlignment=NSTextAlignmentCenter;
    self.jyzLabel.textColor = [UIColor grayColor];
    self.jyzLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:self.jyzLabel];
    
    self.jyzButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:self.jyzButton];
    [self.jyzButton addTarget:self action:@selector(jyzButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.jyzxxView = [[UIView alloc] init];
    self.jyzxxView.layer.cornerRadius = 5;
    self.jyzxxView.backgroundColor = [UIColor grayColor];
    self.jyzxxView.hidden = YES;
    [self.view addSubview:self.jyzxxView];
    
    if ([self.colorStr isEqualToString:@"1"]) {
        
        [self.tuButton setTitleColor:[UIColor blueColor]forState:UIControlStateNormal];
        [self.biaoButton setTitleColor:[UIColor grayColor]forState:UIControlStateNormal];
        
    }else if ([self.colorStr isEqualToString:@"2"]){
        
        [self.biaoButton setTitleColor:[UIColor grayColor]forState:UIControlStateNormal];
        [self.tuButton setTitleColor:[UIColor blueColor]forState:UIControlStateNormal];
        
    }else if ([self.colorStr isEqualToString:@"3"]){
        
        [self.biaoButton setTitleColor:[UIColor blueColor]forState:UIControlStateNormal];
        [self.tuButton setTitleColor:[UIColor grayColor]forState:UIControlStateNormal];
        
    }
    
    
    if (IS_IPHONE5) {
        [self.syLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view).with.offset(kNavbarHeight+60);
            make.centerX.equalTo(self.view);
        }];
        
        
    }else {
        
        [self.syLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view).with.offset(kNavbarHeight+80);
            make.centerX.equalTo(self.view);
        }];
        
    }
    
    [self.syGposLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.syLabel.mas_bottom).with.offset(14);
        make.centerX.equalTo(self.view);
    }];
    
    [self.kjLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.syGposLabel.mas_bottom).with.offset(30);
        make.left.equalTo(self.view).with.offset(KmainScreenWidth/3-60);
    }];
    
    [self.kjnrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.kjLabel);
        make.left.equalTo(self.kjLabel.mas_right).with.offset(5);
    }];
    
    
    [jxLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.syGposLabel.mas_bottom).with.offset(30);
        make.right.equalTo(self.view).with.offset(-KmainScreenWidth/3);
    }];
    
    [self.jxnrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(jxLabel);
        make.left.equalTo(jxLabel.mas_right).with.offset(5);
    }];
    
    [tbBjView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(jxLabel.mas_bottom).with.offset(25);
        make.centerX.equalTo(self.view);
        make.width.equalTo(@150);
        make.height.equalTo(@40);
    }];
    
    
    [sxView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tbBjView).with.offset(10);
        make.bottom.equalTo(tbBjView.mas_bottom).with.offset(-10);
        make.centerX.equalTo(tbBjView);
        make.width.equalTo(@1);
        
    }];
    
    [self.tuButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tbBjView).with.offset(0);
        make.left.equalTo(tbBjView).with.offset(0);
        make.right.equalTo(sxView.mas_left).with.offset(0);
        make.bottom.equalTo(tbBjView).with.offset(0);
        
    }];
    
    [self.biaoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tbBjView).with.offset(0);
        make.right.equalTo(tbBjView).with.offset(0);
        make.left.equalTo(sxView.mas_right).with.offset(0);
        make.bottom.equalTo(tbBjView).with.offset(0);
        
    }];
    
    [self.bottomBjtView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tbBjView).with.offset(70);
        make.left.equalTo(self.view).with.offset(10);
        make.right.equalTo(self.view).with.offset(-10);
        make.bottom.equalTo(self.view).with.offset(-20);
        
    }];
    
    [self.jtImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tbBjView.mas_bottom).with.offset(20);
        make.right.equalTo(self.view).with.offset(-10);
        //        make.width.equalTo(@80);
        
    }];
    
    [self.jyzLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.jtImageView);
        make.right.equalTo(self.jtImageView.mas_left).with.offset(-5);
        //        make.width.equalTo(@80);
        
    }];
    
    [self.jyzButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tbBjView.mas_bottom).with.offset(17);
        make.right.equalTo(self.view).with.offset(-10);
        make.width.equalTo(@60);
        make.height.equalTo(@20);
    }];
    
    [self.jyzxxView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.jyzButton).with.offset(15);
        make.right.equalTo(self.view).with.offset(0);
        make.width.equalTo(@80);
        make.height.equalTo(@124);
        
    }];
    
    NSLog(@"model---%@",self.modelArr);
    if (self.modelArr.count ==0) {
        if ([self.isOn isEqualToString:@"0"]) {
            self.syLabel.text = @"总收益";
        }else {
            self.syLabel.text = @"昨日收益";
            
        }
        

        NSLog(@"1");
    }else {
        if ([self.isOn isEqualToString:@"0"]) {
            
            self.syLabel.text = [NSString stringWithFormat:@"总收益(%d)",[self.modelArr[0] datatime]];
//            NSNumber * nsNumber1 = @([self.modelArr[0] totalIncome]);
            self.syGposLabel.text = [NSString stringWithFormat:@"%@",[self.modelArr[0] totalIncome]];
//            NSNumber * nsNumber2 = @([self.modelArr[0] minerTotalIncome]);
            self.kjnrLabel.text =[NSString stringWithFormat:@"%@",[self.modelArr[0] minerTotalIncome]];
//             NSNumber * nsNumber3 = @([self.modelArr[0] campaignTotalIncome]);
            self.jxnrLabel.text = [NSString stringWithFormat:@"%@",[self.modelArr[0] campaignTotalIncome]];
            //        NSLog(@"model---%@",self.modelArr[0]);
            
        }else {
            
            self.syLabel.text = [NSString stringWithFormat:@"昨日收益(%d)",[self.modelArr[0] datatime]];
            self.syGposLabel.text = [NSString stringWithFormat:@"%@",[self.modelArr[0] yesterdayTotal]];
//            NSNumber * nsNumber2 = @([self.modelArr[0] minerIncome]);
            self.kjnrLabel.text =[NSString stringWithFormat:@"%@",[self.modelArr[0] minerIncome]];
//            NSNumber * nsNumber3 = @([self.modelArr[0] campaignIncome]);
            self.jxnrLabel.text = [NSString stringWithFormat:@"%@",[self.modelArr[0] campaignIncome]];
        }

        NSLog(@"2");
        
    }
//     [self tuLoadView];
    self.jyzLabel.text = self.option;
    self.kjLabel.text = @"GPOS智能";
    jxLabel.text = @"竞选";

   
}

- (void)bottomLoadView {
    
    UILabel * oneheaderLabel = [[UILabel alloc] init];
    oneheaderLabel.textAlignment=NSTextAlignmentCenter;
    oneheaderLabel.textColor = [UIColor blackColor];
    oneheaderLabel.backgroundColor = [UIColor grayColor];
    oneheaderLabel.font = [UIFont systemFontOfSize:14];
    [self.bottomBjtView addSubview:oneheaderLabel];
    
    UIView * hjView = [[UIView alloc] init];
    [self.bottomBjtView addSubview:hjView];
    
    
    UILabel * twoheaderLabel = [[UILabel alloc] init];
    twoheaderLabel.textAlignment=NSTextAlignmentCenter;
    twoheaderLabel.textColor = [UIColor blackColor];
    twoheaderLabel.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];
    twoheaderLabel.font = [UIFont systemFontOfSize:14];
    [hjView addSubview:twoheaderLabel];
    
    
    
    
    UILabel * threeheaderLabel = [[UILabel alloc] init];
    threeheaderLabel.textAlignment=NSTextAlignmentCenter;
    threeheaderLabel.textColor = [UIColor blackColor];
    threeheaderLabel.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];
    threeheaderLabel.font = [UIFont systemFontOfSize:14];
    [hjView addSubview:threeheaderLabel];
    
    UILabel * fourheaderLabel = [[UILabel alloc] init];
    fourheaderLabel.textAlignment=NSTextAlignmentCenter;
    fourheaderLabel.textColor = [UIColor blackColor];
    fourheaderLabel.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];
    fourheaderLabel.font = [UIFont systemFontOfSize:14];
    [hjView addSubview:fourheaderLabel];
    
    self.tableView = [[UITableView alloc] init];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    

    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(fourheaderLabel.mas_bottom).with.offset(1);
        make.left.equalTo(self.bottomBjtView).with.offset(1);
        make.right.equalTo(self.bottomBjtView).with.offset(-1);
        make.bottom.equalTo(self.bottomBjtView).with.offset(-kBottomSafeHeight);
        
    }];
    
    oneheaderLabel.text = @"日期";
    twoheaderLabel.text = @"GPOS智能";
    threeheaderLabel.text = @"竞选";
    fourheaderLabel.text = @"合计";
    
    [oneheaderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomBjtView).with.offset(20);
        make.left.equalTo(self.bottomBjtView).with.offset(1);
        make.height.equalTo(@30);
        make.width.equalTo(@100);
    }];
    
    [hjView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomBjtView).with.offset(20);
        make.left.equalTo(oneheaderLabel.mas_right).with.offset(-1);
        make.right.equalTo(self.bottomBjtView).with.offset(1);
        make.height.equalTo(@30);
    }];
    
    [@[twoheaderLabel, threeheaderLabel,fourheaderLabel] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:1 leadSpacing:1 tailSpacing:1];
    
    [@[oneheaderLabel, twoheaderLabel, threeheaderLabel,fourheaderLabel] mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.left.equalTo(oneheaderLabel.mas_right).with.offset(1);
        make.top.equalTo(hjView).with.offset(0);
        make.height.equalTo(@30);
        //        make.width.mas_equalTo(oneheaderLabel.mas_width);
        
    }];
    self.bottomBjtView.hidden = YES;
    self.tableView.hidden = YES;
    [self tuLoadView];
}

-(void)tuLoadView{
//    self.timeArr = (NSMutableArray *)[[self.timeArr reverseObjectEnumerator] allObjects];
    self.tuView = [[UIView alloc] init];
    self.tuView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tuView];
    [self.tuView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomBjtView).with.offset(19);
        make.left.equalTo(self.view).with.offset(0);
        make.right.equalTo(self.view).with.offset(0);
        make.bottom.equalTo(self.view).with.offset(-kBottomSafeHeight);
//        make.height.equalTo(@200);
        
    }];

    
    if (IS_IPHONESE) {
        
          self.chartView = [[YKLineChartView alloc] initWithFrame:CGRectMake(10, 10, [UIScreen mainScreen].bounds.size.width-20, 180)];
    }else{
        
        self.chartView = [[YKLineChartView alloc] initWithFrame:CGRectMake(10, 50, [UIScreen mainScreen].bounds.size.width-20, 200)];
    }
    
    
    [self.tuView addSubview:self.chartView];
    
    UILabel * leftlabel = [[UILabel alloc] init];
    leftlabel.textColor = [UIColor grayColor];
    leftlabel.text = [self.timeArr firstObject];
    leftlabel.font = [UIFont systemFontOfSize:13.f];
    [self.tuView addSubview:leftlabel];
    [leftlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.chartView.mas_bottom).with.offset(-10);
        make.left.equalTo(self.chartView).with.offset(5);
    }];
    
    UILabel * rightlabel = [[UILabel alloc] init];
    rightlabel.textColor = [UIColor grayColor];
    rightlabel.text = [self.timeArr lastObject];
    rightlabel.font = [UIFont systemFontOfSize:13.f];
    [self.tuView addSubview:rightlabel];
    [rightlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.chartView.mas_bottom).with.offset(-10);
        make.right.equalTo(self.chartView).with.offset(-5);
    }];
    //y轴
    YKUIConfig *config = [YKUIConfig new];
    config.yDescFront = [UIFont fontWithName:@"PingFang-SC-Medium" size:10.0f];
    //    config.yDescColor = [UIColor colorWithRed:204.0f/255.0f green:204.0f/255.0f blue:204.0f/255.0f alpha:1.0f];
    config.yDescColor = [UIColor grayColor];
    //    config.ylineColor =  [UIColor colorWithRed:204.0f/255.0f green:204.0f/255.0f blue:204.0f/255.0f alpha:0.3f];
    config.ylineColor = [UIColor grayColor];
    
    //x轴
    config.xDescFront = [UIFont fontWithName:@"PingFang-SC-Medium" size:10.0f];
//    config.xDescColor = [UIColor colorWithRed:204.0f/255.0f green:204.0f/255.0f blue:204.0f/255.0f alpha:1.0f];
    config.xDescColor = [UIColor grayColor];
    //线
    config.lineWidth = 1;
    config.lineColor = [UIColor blueColor];
    config.circleWidth = 2;
    
    YKLineDataObject *dataObject = [YKLineDataObject new];
    dataObject.ySuffix = @"";
    
    if ([self.colorStr isEqualToString:@"1"]) {
        
        
    }else if ([self.colorStr isEqualToString:@"2"]){
        self.bottomBjtView.hidden = YES;
        self.tableView.hidden = YES;
        self.tuView.hidden = NO;
        
    }else if ([self.colorStr isEqualToString:@"3"]){
        
        self.bottomBjtView.hidden = NO;
        self.tableView.hidden = NO;
        self.tuView.hidden = YES;
        
        
    }
    
    dataObject.xDescriptionDataSource = self.timeArr;
   
    if ([self.isOn isEqualToString:@"0"]) {
        
//         self.NumberArr = (NSMutableArray *)[[self.NumberArr reverseObjectEnumerator] allObjects];
//        homeModel *mo=[[homeModel alloc] init];
//        NSMutableArray *array=[NSMutableArray new];
//        for (mo in self.modelArr)
//        {
//            [array addObject:mo.totalIncome];
//        }
//         array = (NSMutableArray *)[[array reverseObjectEnumerator] allObjects];
         dataObject.showNumbers = self.NumberArr;
        NSLog(@"---%@",self.NumberArr);
    }else {
//        self.NumberArr1 = (NSMutableArray *)[[self.NumberArr1 reverseObjectEnumerator] allObjects];
         dataObject.showNumbers = self.NumberArr1;
    }
   
    [self.chartView setupDataSource:dataObject withUIConfgi:config];
    
   
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.modelArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{//rankingCell
    
    earningViewCell * cell = [[earningViewCell alloc] init];
    if (indexPath.section == 0) {
        
        
        cell = [tableView dequeueReusableCellWithIdentifier:@"earningCell"];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"earningViewCell" owner:self options:nil] firstObject];
        }
        
        
    }
    if ([self.isOn isEqualToString:@"0"]) {
//        NSNumber * nsNumber1 = @([self.modelArr[indexPath.row] minerTotalIncome]);
        cell.kuangjiLable.text = [NSString stringWithFormat:@"%@",[self.modelArr[indexPath.row] minerTotalIncome]];
        cell.riqiLable.text = [NSString stringWithFormat:@"%d",[self.modelArr[indexPath.row] datatime]];
//        NSNumber * nsNumber2 = @([self.modelArr[indexPath.row] campaignTotalIncome]);
        cell.jingxuanLable.text = [NSString stringWithFormat:@"%@",[self.modelArr[indexPath.row] campaignTotalIncome]];
//        NSNumber * nsNumber3 = @([self.modelArr[indexPath.row] totalIncome]);
        cell.hejiLable.text = [NSString stringWithFormat:@"%@",[self.modelArr[indexPath.row] totalIncome]];
        
    }else {
//        cell.kuangjiLable.text = [NSString stringWithFormat:@"%.2f",[self.modelArr[indexPath.row] minerIncome]];
        cell.riqiLable.text = [NSString stringWithFormat:@"%d",[self.modelArr[indexPath.row] datatime]];
//        cell.jingxuanLable.text = [NSString stringWithFormat:@"%.2f",[self.modelArr[indexPath.row] campaignIncome]];
//        cell.hejiLable.text = [NSString stringWithFormat:@"%.2f",[self.modelArr[indexPath.row] yesterdayTotal]];
        
//        NSNumber * nsNumber1 = @([self.modelArr[indexPath.row] minerIncome]);
        cell.kuangjiLable.text = [NSString stringWithFormat:@"%@",[self.modelArr[indexPath.row] minerIncome]];
        
//        NSNumber * nsNumber2 = @([self.modelArr[indexPath.row] campaignIncome]);
        cell.jingxuanLable.text = [NSString stringWithFormat:@"%@",[self.modelArr[indexPath.row] campaignIncome]];
//        NSNumber * nsNumber3 = @([self.modelArr[indexPath.row] yesterdayTotal]);
        cell.hejiLable.text = [NSString stringWithFormat:@"%@",[self.modelArr[indexPath.row] yesterdayTotal]];
        
    }
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 30;
}
//图表按钮
- (void)tuButtonAction:(UIButton *)sender {
    self.colorStr = @"2";
    [self.biaoButton setTitleColor:[UIColor grayColor]forState:UIControlStateNormal];
    [self.tuButton setTitleColor:[UIColor blueColor]forState:UIControlStateNormal];
    self.bottomBjtView.hidden = YES;
    self.tableView.hidden = YES;
    self.tuView.hidden = NO;
    
    
}

- (void)biaoButtonAction:(UIButton *)sender {
    self.colorStr = @"3";
    [self.tuButton setTitleColor:[UIColor grayColor]forState:UIControlStateNormal];
    [self.biaoButton setTitleColor:[UIColor blueColor]forState:UIControlStateNormal];
    
    self.bottomBjtView.hidden = NO;
    self.tableView.hidden = NO;
    self.tuView.hidden = YES;
}

- (void)jyzButtonAction:(UIButton *)sender{
    
    [PopupView addCellWithIcon:nil text:@"近一周" action:^{
        if (self.modelArr.count==0) {
            return;
        }
        self.number = @"7";
        self.option = @"近一周";
        
        self.jyzLabel.text = @"";
        [self.tuView removeFromSuperview];
//        [self.bottomBjtView removeFromSuperview];
        [self.tableView reloadData];
        [self tuData];
       
        NSLog(@"别点第一个");
    }];
    [PopupView addCellWithIcon:nil text:@"近一月" action:^{
        if (self.modelArr.count==0) {
            return;
        }
        self.number = @"30";
        self.option = @"近一月";
       
        self.jyzLabel.text = @"";
        [self.tuView removeFromSuperview];
//        [self.bottomBjtView removeFromSuperview];
        [self.tableView reloadData];
        [self tuData];
        NSLog(@"别点第二个");
    }];
    [PopupView addCellWithIcon:nil text:@"近三月" action:^{
        if (self.modelArr.count==0) {
            return;
        }
        self.number = @"90";
        self.option = @"近三月";
        
        self.jyzLabel.text = @"";
        [self.tuView removeFromSuperview];
//        [self.bottomBjtView removeFromSuperview];

        [self.tableView reloadData];
        [self tuData];
        NSLog(@"别点第3个");
    }];
    [PopupView addCellWithIcon:nil text:@"近半年" action:^{
        if (self.modelArr.count==0) {
            return;
        }

        self.number = @"180";
        self.option = @"近半年";
        self.jyzLabel.text = @"";
        [self.tuView removeFromSuperview];
//        [self.bottomBjtView removeFromSuperview];
        [self.tableView reloadData];
        [self tuData];
        NSLog(@"别点第4个");
    }];
    [PopupView addCellWithIcon:nil text:@"全部" action:^{
        if (self.modelArr.count==0) {
            return;
        }
        self.number = @"-1";
        self.option = @"全部";
        self.jyzLabel.text = @"";
        [self.tuView removeFromSuperview];
//        [self.bottomBjtView removeFromSuperview];
        [self.tableView reloadData];

        [self tuData];
        NSLog(@"别点第5个");
    }];
    [PopupView popupViewInButton:sender];
}




- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed=YES;
    }
    return self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
